package com.onlyphoto.onlymall.mvp.view.viewholder

import android.annotation.SuppressLint
import android.content.Intent
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.onlyphoto.onlymall.R
import com.bumptech.glide.Glide
import com.onlyphoto.onlymall.bean.response.GoodsBean
import com.onlyphoto.onlymall.mvp.view.activity.GoodsDetailsActivity

/**
 * Created by gaochujia on 2019-07-17.
 */
class GoodsItemHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    var img: ImageView? = null
    var title: TextView? = null
    var gift: TextView? = null
    var price: TextView? = null

    init {
        img = itemView.findViewById(R.id.img_goods)
        title = itemView.findViewById(R.id.title)
        gift = itemView.findViewById(R.id.gift)
        price = itemView.findViewById(R.id.price)
    }

    @SuppressLint("SetTextI18n")
    fun loadData(bean: GoodsBean) {
        Glide.with(img!!.context).load(bean.front_img).placeholder(R.mipmap.img_default).into(img!!)
        title?.text = bean.title
        if (bean.gift_set == 1) {
            gift?.visibility = View.VISIBLE
        } else {
            gift?.visibility = View.GONE
        }
        price?.text = "¥ " + bean.price_now.toString()
        itemView.setOnClickListener{
            itemView.context.startActivity(Intent(itemView.context, GoodsDetailsActivity::class.java)
                    .putExtra("goodsId", bean.id))
        }
    }
}
